#include "Application.h"

#include <QDebug>
#include <QJsonArray>
#include <QMessageBox>
#include <QTimer>
#include <QtConcurrent/QtConcurrentRun>
#include <cstddef>
#include <data/UserInfo.pb.h>
#include <loginform/loginform.h>
#include <mainwindow/mainwindow.h>
#include <method/Method.pb.h>
#include <method/Request.pb.h>
#include <method/Response.pb.h>
#include <openssl/OpenSSL.h>
#include <qapplication.h>
#include <qobject.h>

using namespace proto;

// 静态变量
Application* Application::m_app = nullptr;
QString      TCP_SERVER_ADDR    = "127.0.0.1";
// QString      TCP_SERVER_ADDR    = "192.168.159.128";
int TCP_SERVER_PORT = 4090;

Application::Application() {
    if (!m_app)
        m_app = this;
    QApplication::setWindowIcon(QIcon(":/resource/img/app/qq.ico"));
    LoginForm* loginForm = new LoginForm();
    mainwindow           = new MainWindow();
    loginForm->show();

    connectToHost(TCP_SERVER_ADDR, TCP_SERVER_PORT);
}
Application::~Application() {}

void Application::onTryConnect() {
    connectToHost(TCP_SERVER_ADDR, TCP_SERVER_PORT);
}

Application* Application::instance() { return m_app; }

const data::UserInfo& Application::Myself() {
    auto* app = instance();
    return app->myself;
}
